package com.beetlestech.nfe.main.biz.com.impl;
import java.util.ArrayList;
import java.util.List;
import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.fw.core.util.StringUtil;
import com.beetlestech.nfe.main.biz.com.HbVHomeWorkListForTeacher;
import com.beetlestech.nfe.main.biz.com.dto.VhomeworklistforteacherInfoDTO;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.base.StatementDTO;
import com.beetlestech.nfe.main.db.base.StatementUtil;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.view.VhomeworklistforteacherDTO;
public class HbVHomeWorkListForTeacherImpl extends AbstractDBLogic implements HbVHomeWorkListForTeacher, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {

	@SuppressWarnings("unused")
	@Override
	public VhomeworklistforteacherInfoDTO[] getHomeWorkListForTeacher(
			Integer teacherId,
			String homeWorkName,
			String studentName,
			Integer courseTypeId,
			String sendStart,
			String sendEnd
			) {
		Integer a=-1;
		List<VhomeworklistforteacherInfoDTO> homeWorkList = new ArrayList<VhomeworklistforteacherInfoDTO>();
		//List<VstudentlistforteacherInfoDTO> studentListReturn = new ArrayList<VstudentlistforteacherInfoDTO>();
		List<VhomeworklistforteacherDTO> homeWorkListDB = new ArrayList<VhomeworklistforteacherDTO>();
		VhomeworklistforteacherDTO vhomeworklistDTO =new VhomeworklistforteacherDTO();
		StatementDTO statementDTO = new StatementDTO();
		if(teacherId!=null && teacherId!=0){
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_TEACHER_ID, StatementUtil.KEYWORD.EQUAL ,teacherId);

		}
		if(StringUtil.isNotEmpty(homeWorkName)){
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_HOMEWORKNAME, StatementUtil.KEYWORD.LIKE ,homeWorkName);
		}
		if(StringUtil.isNotEmpty(studentName)){
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_STUDENTNAME, StatementUtil.KEYWORD.LIKE ,studentName);
		}
		
		if(courseTypeId!=0){
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_CATAGORY_C_ID, StatementUtil.KEYWORD.EQUAL ,courseTypeId);
		}
        if(!StringUtil.isEmpty(sendStart) &&!StringUtil.isEmpty(sendEnd)){
			
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_SEND_DATE, StatementUtil.KEYWORD.GREATER_EQUAL_THAN ,sendStart);
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_SEND_DATE, StatementUtil.KEYWORD.LESS_EQUAL_THAN ,sendEnd);
		}else if((sendStart==null || sendStart.equals("")) &&(sendEnd!=null && !sendEnd.equals(""))){
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_SEND_DATE, StatementUtil.KEYWORD.LESS_EQUAL_THAN ,sendEnd);
		}else if((sendStart!=null && !sendStart.equals("")) &&(sendEnd==null || sendEnd.equals(""))){
			StatementUtil.andWhere(statementDTO, VhomeworklistforteacherDTO.COLUMN_SEND_DATE, StatementUtil.KEYWORD.GREATER_EQUAL_THAN ,sendStart);
		}
        vhomeworklistDTO.set_dynamicWhereCondition(statementDTO.getSQLStatement());
        homeWorkListDB=queryDAO.queryForObjectList(VhomeworklistforteacherDTO.SQL_SEARCH, vhomeworklistDTO);
		if(homeWorkListDB==null || homeWorkListDB.size()==0){
			createApplicationException("errMsg", "没找到要查询的信息");
		}else{
			for(VhomeworklistforteacherDTO item:homeWorkListDB){
				homeWorkList.add(convertToVhomeWorkListInfo(item));
			}
		}
     
	    return  homeWorkList.toArray(new VhomeworklistforteacherInfoDTO[homeWorkList.size()]);
		
	}
	private VhomeworklistforteacherInfoDTO convertToVhomeWorkListInfo(VhomeworklistforteacherDTO item){
		VhomeworklistforteacherInfoDTO vhomeworklistforteacherInfoDTO =new VhomeworklistforteacherInfoDTO();
		vhomeworklistforteacherInfoDTO.sethistoryid(item.gethistoryid());
		vhomeworklistforteacherInfoDTO.setstudentname(item.getstudentname());
		vhomeworklistforteacherInfoDTO.sethomeworkname(item.gethomeworkname());
		vhomeworklistforteacherInfoDTO.setcatagorycname(item.getcatagorycname());
		vhomeworklistforteacherInfoDTO.setsenddate(item.getsenddate());
		vhomeworklistforteacherInfoDTO.setsendtime(item.getsendtime());
		vhomeworklistforteacherInfoDTO.setmessage(item.getmessage());
		vhomeworklistforteacherInfoDTO.setstate(item.getstate());
		return vhomeworklistforteacherInfoDTO;
	}

	
}
